Repository navigation
fix: Await pending refresh before sending new requests - #142
StarProxima wants to merge 1 commit into
Conversation
768eae0 to
08b7757
Compare
|
Note on pana check failure: The Once the updated |
08b7757 to
812bb0b
Compare
QueuedInterceptor (Dio) runs onRequest and onError on separate queues, so new requests can pass through onRequest with a stale token while onError is processing a refresh. The same issue applies to fresh_http and fresh_graphql where send()/request() are fully concurrent. Add tokenWaitingRefresh getter to FreshMixin that awaits _refreshFuture (if present) without starting a new refresh. Use it in onRequest (fresh_dio), send() (fresh_http), and request() (fresh_graphql) to wait for any in-flight refresh before reading the token. This eliminates unnecessary 401/UNAUTHENTICATED responses for requests arriving during the refresh window.
812bb0b to
297f68d
Compare
|
@felangel @passsy gentle ping on this. It makes requests wait for a refresh already in progress instead of going out with a stale token. The branch is still up to date with |
Summary
Fixes #141 - New requests sent with stale token while refresh is in-flight.
tokenWaitingRefreshgetter toFreshMixinthat awaits_refreshFuturewithout starting a new refreshonRequest(fresh_dio),send()(fresh_http), andrequest()(fresh_graphql) before reading the tokenProblem
QueuedInterceptor(Dio) runsonRequestandonErroron separate queues. WhileonErroris awaiting a token refresh, new requests pass throughonRequestwith the old (already invalidated) token, causing unnecessary 401 round-trips. The same applies tofresh_httpandfresh_graphqlwheresend()/request()are fully concurrent.PR #130 correctly prevents multiple parallel
refreshTokencalls, but does not prevent new requests from being dispatched with a stale token during the refresh window.Solution
A single new getter in
FreshMixin:It piggy-backs on the existing
_refreshFuturefrom #130, no new dependencies, no changes to the refresh lifecycle.This is kept as a separate getter from
tokenintentionally: merging the waiting logic intotokenwould risk deadlocks ifperformTokenRefreshimplementations ever readtoken.Changes
fresh/lib/src/fresh.darttokenWaitingRefreshtoFreshMixinfresh_dio/lib/src/fresh.dartonRequest:await token→await tokenWaitingRefreshfresh_http/lib/src/fresh.dartsend():await token→await tokenWaitingRefreshfresh_graphql/lib/src/fresh_link.dartrequest():await token→await tokenWaitingRefreshTest Coverage
Added 2 tests per package (fresh_dio, fresh_http, fresh_graphql) - 6 total:
_Unfixed*subclass overridingtokenWaitingRefresh → token)totalErrorCount == 2)Fresh/FreshLink)totalErrorCount == 1)Test Results
fresh: 33 tests ✅fresh_dio: 46 tests ✅fresh_http: 43 tests ✅fresh_graphql: 31 tests ✅All existing tests pass, no lint warnings.
Checklist